﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Abp.AutoMapper;
using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using Hicap.AuthorizationServer.Core.Caches.Base.Interface;
using Hicap.AuthorizationServer.Core.Caches.Sys;
using Hicap.AuthorizationServer.Core.Caches.Sys.Interface;
using Hicap.AuthorizationServer.Core.Models.Sys;
using Hicap.AuthorizationServer.Sys.AppService.Interface;
using Hicap.AuthorizationServer.Sys.DTO.Comapnys;
using Microsoft.AspNetCore.Authorization;

namespace Hicap.AuthorizationServer.Sys.AppService
{
    /// <summary>
    /// Company应用层服务的接口实现方法
    ///</summary>
    public class CompanyAppService : AuthorizationServerAppServiceBase<Company, CompanyAppService, CompanyEditDto, CompanyListDto, CompanyCacheItem>, ICompanyAppService
    {
        private readonly IRepository<Company> _repository;

        public CompanyAppService(IRepository<Company> repository, IUnitOfWorkManager unitOfWorkManager, ICompanyCache cache) : base(repository, unitOfWorkManager, cache)
        {
            _repository = repository;
            QueryCondition = (x) => x.IsActive == true;
        }

        [AllowAnonymous]
        public async Task<List<CompanyListDto>> GetAllCompanys()
        {
            var entities = await _repository.GetAllListAsync();
            return entities.MapTo<List<CompanyListDto>>();
        }
    }
}